<?php

namespace app\index\controller;

use think\Controller;
use think\Model;

class Curl extends Base
{

        function request_post($url, $param)
        {
                if (empty($url) || empty($param)) {
                        return false;
                }
                //初始化
                $curl = curl_init();
                //设置抓取的url
                curl_setopt($curl, CURLOPT_URL, $url);
                //设置头文件的信息作为数据流输出
                curl_setopt($curl, CURLOPT_HEADER, 1);
                //设置获取的信息以文件流的形式返回，而不是直接输出。
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                //设置post方式提交
                curl_setopt($curl, CURLOPT_POST, 1);

                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
                curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
                curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 6);
                curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
                //设置post数据
                $post_data = $param;
                //post提交的数据
                curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
                //执行命令
                $data = curl_exec($curl);
                //关闭URL请求
                curl_close($curl);
                //显示获得的数据
                /*echo($data);*/
        }
}
